Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 5th No.28】为 Paddle 新增 slice_scatter API #784

Merged
merged 4 commits into from
Dec 15, 2023

Conversation

megemini
Copy link
Contributor

PR types

Others

PR changes

Docs

Description

【Hackathon 5th No.28】为 Paddle 新增 slice_scatter API

参考 #668 中的讨论,实现方案与其不同,采用 scatter 的方式实现,并做以下几点说明:

  • x 与 src 需要有相同的 ndim
  • src_shape 需要与 slice 的 exp_shape 一致
  • 因为 paddle.scatter 没有 axis 参数,所以需要 transpose
  • 参数 axis/start/stop/step 不支持 list。因为,多个 axis 的话可能导致 slice 的 shape 错误。
    比如,x 为 [8, 8], src 为 [8, 2],则 axis 只能为 1。
  • 由于依赖 paddle.scatter,而此接口只支持 float32 和 float64,因此,具体支持的数据类型待验证。

以上在 RFC 中第五章也有写 ~

@VOIDMalkuth 感谢您的 RFC ,参考了 PyTorch 调研以及之前的部分,如果已经实现代码了,尽快提交啊 ~~~ 🤗🤗🤗

@zoooo0820 请评审 ~ 非常感谢!

Copy link

paddle-bot bot commented Dec 13, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请检查PR提交格式和内容是否完备,具体请参考示例模版
Your PR has been submitted. Thanks for your contribution!
Please check its format and content. For this, you can refer to Template and Demo.


## API实现方案

此次使用 scatter 的方式实现接口,但是由于 `paddle.scatter` 缺少 `axis` 参数,因此需要内部进行转换:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里其实调用set_value算子更合适一些,可以参考下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_value 是不是修改底层实现了啊?!看到 select_scatter 的实现方式,太简单了 ~~~ 🤣🤣🤣


添加 Python API:
```python
paddle.slice_scatter(x, src, axis=0, start=None, stop=None, step=1, name=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据赋值的语义,是否src改成value更合适一些。

@megemini
Copy link
Contributor Author

Update 20231214

  • 修改实现方案为 set_value

@zoooo0820 请评审 ~

@VOIDMalkuth
Copy link

你好,我这边由于个人事务原因可能没有更多精力开发了,欢迎你接手这一工作。我此前根据单一输入的版本完成了部分代码,但还不够完善,因此也就不提交成PR了,在此给出Github Gist,希望能给你提供一些参考。

https://gist.github.com/VOIDMalkuth/c03022f63354f8195573a1f280a5b129

Copy link
Contributor

@zoooo0820 zoooo0820 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zoooo0820 zoooo0820 merged commit 3820b91 into PaddlePaddle:master Dec 15, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants